<script>
function delete_event(id, title, url)
{
		// a workaround for a flaw in the demo system (http://dev.jqueryui.com/ticket/4375), ignore!
		jQuery( "#dialog:ui-dialog" ).dialog( "destroy" );
		jQuery( "#dialog-title" ).html(title);	
		jQuery( "#dialog-modal" ).dialog({
			resizable: false,
			height:140,
			modal: true,			
			buttons: {
				"Yes": function() {
					loading_area('<%= image_tag "loading_ajax.gif" %>', "#events-list", ".style1");
					$( this ).dialog( "close" );
					jQuery.ajax({
					  url: url,
					  type: 'DELETE',
					  success: function (data){
					    jQuery.ajax({
					      url: "<%= request.request_uri %>",
						  data: "format=js"
					    });
					  }
					});
				},
				Cancel: function() {
					$( this ).dialog( "close" );
				}
			}

		});
}
</script>

<%= form_tag({:controller => 'events', :action => 'delete_selected'}, :id => 'mainForm') do %>

						  <div class="dataTables_wrapper">
						    <div id="events-list">
						      <table class="style1">

							<thead>
								<tr>
									<th><input type="checkbox" class="checkbox select-all" /></th>
									<th width="25%">Title</th>
									<th width="50%">Description</th>
									<th width="15%" class="column_center">Articles</th>
                                                                        <th width="10%" class="column_center">Controls</th>
									<th class="column_center">Published</th>
								</tr>
							</thead>
							
							<tbody>
                                                          <% @events.each do |event| %>                                                            
                                                                <tr>
									<td><input type="checkbox" class="checkbox" name="ids[<%= event.id %>]" /></td>
									<td><a href="#"><%= link_to event.title, event %></a></td>

									<td><%= event.description %></td>
									<td align="center"><%= event.articles_count %></td>
									<td align="center">
                                                                          <%= link_to image_tag("ico_edit_16.png", :border=>0, :class => 'icon16 fl-space2', :title => 'Edit'), edit_event_path(event) %>
                                                                          <span class="delete">
									    <%= image_tag("ico_delete_16.png",
						                                          :border=>0,
											  :class => 'icon16 fl-space2',
											  :title => 'Delete',
											  :onClick => "delete_event(#{event.id}, '#{event.title}', '#{url_for(event)}');",
											  :style => "cursor:pointer") %>
									  </span>
                                                                          <%= link_to image_tag("ico_new_article_16.png", :border=>0, :class => 'icon16 fl-space2', :title => 'New article for this event'), new_article_path(:event_id => event) %>									  
									</td>
									<td align="center">
									  <span id="published_<%= event.id %>" class="published">
									    <%=
									      if event.published
										link_to image_tag("published_on.png", :border=>0, :class => 'icon16 fl-space2', :title => 'Yes'),										      
											    { :controller => "events", :id => event.id,										      
											    :action => "published", :format => "js"},
											    :remote => true
									      else
										link_to image_tag("published_off.png", :border=>0, :class => 'icon16 fl-space2', :title => 'No'),										      
											    { :controller => "events", :id => event.id,										      
											    :action => "published", :format => "js"},
											    :remote => true
									      end
									    %>
									  </span>									  
									</td>
								</tr>
                                                          <% end %>
                                                          </tbody>
						      </table>
						    </div>
						      
						<div class="tab-footer clear">
						  <div class="dataTables_paginate paging_full_numbers">
                                                        <%= will_paginate(@events, :renderer => "PaginationListLinkRenderer") %>
						  </div>
                                                        <script type="text/javascript">
        
                                                          jQuery(document).ready(function() {
                                                            jQuery('.pagination a').attr('data-remote', 'true');
                                                            jQuery('.pagination a').attr('update', 'dd');
							    jQuery('.pagination a').click(function() {
										      loading_area('<%= image_tag "loading_ajax.gif" %>', "#events-list", ".style1");
										    });
							    jQuery('#events .checkbox.select-all').click(function() {
										      //alert(jQuery('#articles .checkbox.select-all').is(':checked'));
										      jQuery("#events .checkbox").attr("checked", jQuery('#events .checkbox.select-all').is(':checked'));										      
										    });
							    
							    jQuery('.published').click(function() {
										      //alert(jQuery('#articles .checkbox.select-all').is(':checked'));
										      //jQuery('.published').html('<div class="loading"><%= image_tag "loading_ajax.gif" %></div>');
										      this.innerHTML = '<div class="published_loading"><%= image_tag "published_ajax.gif" %></div>';
										    });
							    
                                                          });
        
                                                        </script>							
						</div>
						  </div>

<% end %>